package com.epfresh.supplier.adapter;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.DeliveryItem;
import com.epfresh.supplier.widget.RecyclerViewAdapter;

import java.util.ArrayList;

/**
 * Created by zhuli on 2017/8/22.
 */

public class CustomerDeliveryAdapter extends RecyclerViewAdapter<DeliveryItem> {


    /**
     * 构造方法
     *
     * @param data 数据
     */
    public CustomerDeliveryAdapter(ArrayList<DeliveryItem> data) {
        super(data);
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new CustomerDeliveryViewHolder(view, false);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        return new CustomerDeliveryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_customer_delivery, parent, false), isItem);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, boolean isItem) {
        CustomerDeliveryViewHolder viewHolder = (CustomerDeliveryViewHolder) holder;
        DeliveryItem deliveryItem = getItem(position);
        viewHolder.tvName.setText(deliveryItem.getName());
        viewHolder.tvTel.setText(deliveryItem.getPhone());
        viewHolder.tvAdress.setText(deliveryItem.getAddress()+deliveryItem.getAddressOnMap());
        viewHolder.tvNickName.setText(TextUtils.isEmpty(deliveryItem.getNickname())?"无":deliveryItem.getNickname());
    }

    @Override
    public int getSwipeLayoutResourceId(int i) {
        return 0;
    }

    class  CustomerDeliveryViewHolder extends RecyclerViewHolder {
        TextView tvName;
        TextView tvTel;
        TextView tvAdress;
        TextView tvNickName;
        LinearLayout llDelivery;

        public CustomerDeliveryViewHolder(View itemView, boolean isItem) {
            super(itemView, isItem);
            tvName = (TextView) itemView.findViewById(R.id.item_tv_delivery_name);
            tvTel = (TextView) itemView.findViewById(R.id.item_tv_delivery_tel);
            tvAdress = (TextView) itemView.findViewById(R.id.item_tv_delivery_address);
            tvNickName = (TextView) itemView.findViewById(R.id.item_tv_delivery_nick_name);
            llDelivery = (LinearLayout) itemView.findViewById(R.id.ll_delivery);
            itemView.setOnClickListener(null);
            llDelivery.setOnClickListener(this);
        }
    }

}
